import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { LoginPage } from '../login/login';
import { ParkDataProvider } from '../../providers/park-data/park-data';

/**
 * Generated class for the MyPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-my',
  templateUrl: 'my.html',
})
export class MyPage {
  cacheCount: number = 0;
  constructor(public navCtrl: NavController, 
    public navParams: NavParams,
    public storage:Storage,
    public parkDataProvider: ParkDataProvider) {
  }

  ionViewDidLoad() {
  
  }
  ionViewWillEnter(){
    this.parkDataProvider.getCacheCount().then(res=>{
      if(res&& res.rows && res.rows.length>0){
        this.cacheCount = res.rows.item(0).count as number;
      }
    }).catch(()=>{
      console.log('数据表访问错误');
      
    });
  
  }
  /**
   * 推出登录
   */
  logout(){
    this.storage.remove('USER_INFO');
    this.storage.remove('LOGIN_INFO');
    this.navCtrl.setRoot(LoginPage);
  }
  /**
   * 更新缓存
   */
  refreshCache(){
    this.parkDataProvider.setParksToCache();
  }

}
